package com;

import com.Mapper.UserMapper;
import com.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;


import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class MybatisDemo1 {
    public static void main(String[] args) throws IOException {

        //获取sessionFactory工厂对象
        String resource = "mybatis-config.xml";
        InputStream inputstream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputstream);


        //获取Factory构造的Sessoin对象(用于操作持久层，类似于jdbc中的connection)
        SqlSession sqlSession = sqlSessionFactory.openSession();

        //List<User> users = sqlSession.selectList("test.selectAll");

        //获取UserMapper接口的代理对象
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        List<User> users = userMapper.selectAll();
        User user = userMapper.selectById(6);

        System.out.println(users);
        System.out.println(user);

        sqlSession.close();





    }
}
